package com.opennews.openplatform

import groovy.transform.CompileStatic
import org.springframework.http.HttpStatus

@CompileStatic
class AccountGroupController extends BaseController {
    static allowedMethods = [
        update: "POST"
    ]

    AccountGroupService accountGroupService
    IncomeExpenseDetailService incomeExpenseDetailService

    // region: Get actions.
    def index() {
        render("AccountGroupController")
    }

    def queryAccountGroupInfo() {
        def claims = getClaims()
        def accountGroupId = claims.accountGroupId
        def userId = claims.id
        def result = accountGroupService.queryAccountGroupInfo(accountGroupId, userId)

        sendDataResponse(result)
    }

    def queryBasicStatistics() {
        def accountGroupId = getClaims().accountGroupId
        def result = incomeExpenseDetailService.queryBasicStatistics(accountGroupId)

        sendDataResponse(result)
    }
    // endregion

    // region: Post actions.
    def update() {
        def requestBodyData = getRequestBodyData()
        accountGroupService.update(requestBodyData)

        sendStatusResponse(HttpStatus.NO_CONTENT)
    }
    // endregion
}